home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / encodings / hex_codec.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  4KB  |  89 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. """ Python 'hex_codec' Codec - 2-digit hex content transfer encoding
  5.  
  6.     Unlike most of the other codecs which target Unicode, this codec
  7.     will return Python string objects for both encode and decode.
  8.  
  9.     Written by Marc-Andre Lemburg (mal@lemburg.com).
  10.  
  11. """
  12. import codecs
  13. import binascii
  14.  
  15. def hex_encode(input, errors = 'strict'):
  16.     """ Encodes the object input and returns a tuple (output
  17.         object, length consumed).
  18.  
  19.         errors defines the error handling to apply. It defaults to
  20.         'strict' handling which is the only currently supported
  21.         error handling for this codec.
  22.  
  23.     """
  24.     if not errors == 'strict':
  25.         raise AssertionError
  26.     output = None.b2a_hex(input)
  27.     return (output, len(input))
  28.  
  29.  
  30. def hex_decode(input, errors = 'strict'):
  31.     """ Decodes the object input and returns a tuple (output
  32.         object, length consumed).
  33.  
  34.         input must be an object which provides the bf_getreadbuf
  35.         buffer slot. Python strings, buffer objects and memory
  36.         mapped files are examples of objects providing this slot.
  37.  
  38.         errors defines the error handling to apply. It defaults to
  39.         'strict' handling which is the only currently supported
  40.         error handling for this codec.
  41.  
  42.     """
  43.     if not errors == 'strict':
  44.         raise AssertionError
  45.     output = None.a2b_hex(input)
  46.     return (output, len(input))
  47.  
  48.  
  49. class Codec(codecs.Codec):
  50.     
  51.     def encode(self, input, errors = 'strict'):
  52.         return hex_encode(input, errors)
  53.  
  54.     
  55.     def decode(self, input, errors = 'strict'):
  56.         return hex_decode(input, errors)
  57.  
  58.  
  59.  
  60. class IncrementalEncoder(codecs.IncrementalEncoder):
  61.     
  62.     def encode(self, input, final = False):
  63.         if not self.errors == 'strict':
  64.             raise AssertionError
  65.         return None.b2a_hex(input)
  66.  
  67.  
  68.  
  69. class IncrementalDecoder(codecs.IncrementalDecoder):
  70.     
  71.     def decode(self, input, final = False):
  72.         if not self.errors == 'strict':
  73.             raise AssertionError
  74.         return None.a2b_hex(input)
  75.  
  76.  
  77.  
  78. class StreamWriter(Codec, codecs.StreamWriter):
  79.     pass
  80.  
  81.  
  82. class StreamReader(Codec, codecs.StreamReader):
  83.     pass
  84.  
  85.  
  86. def getregentry():
  87.     return codecs.CodecInfo(name = 'hex', encode = hex_encode, decode = hex_decode, incrementalencoder = IncrementalEncoder, incrementaldecoder = IncrementalDecoder, streamwriter = StreamWriter, streamreader = StreamReader)
  88.  
  89.